<template>
  <q-page class="cc-admin row">

    <div class="col bg-white shadow-2 q-pa-md q-ma-sm">
      <q-table
        flat
        color="primary"
        class="cross_table"
        separator="cell"
        :columns="columns"
        :data="list"
        row-key="id"
        :pagination.sync="pagination"
        :visible-columns="group"
        @request="query"
        :rows-per-page-options="[10,20,50,100]"
        :loading="loading"
        selection="multiple"
        :selected.sync="selected"
      >
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-input
              clearable
              outlined
              dense
              placeholder="请输入关键字搜索"
              class="on-left"
              @input="query"
              debounce="500"
              v-model="key"
            >
              <template #append>
                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
          </div>
        </template>
        <template #body-cell-visibility="props">
          <q-td key="visibility" :props="props">
            <q-item v-if="props.row.visibility==1">显示</q-item>
            <q-item v-if="props.row.visibility==0">隐藏</q-item>
          </q-td>
        </template>
        <template #body-cell-top="props">
          <q-td key="top" :props="props">123
            <q-item v-if="props.row.top == 1">显示</q-item>
            <q-item v-if="props.row.top == 0">隐藏</q-item>
          </q-td>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <q-btn flat round dense color="primary" icon="edit" @click="edit(props.row)">
              <q-tooltip>编辑</q-tooltip>
            </q-btn>
            <btn-del label="文章管理" @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>
    <q-dialog maximized flat persistent ref="dialog">
      <q-form @submit="submit" class="dialog_card column">
        <h5 class="view_title justify-between q-px-md">
          {{editType}}文章
          <q-btn  outline round icon="clear" size="sm" v-close-popup />
        </h5>
        <q-scroll-area class="col">
          <div class="row q-col-gutter-x-md dialog_form q-pa-md hidden" >
            <div class="col-3">
              <h5>
                <q-icon name="star" color="red" />文章id：
              </h5>
              <div class=" q-col-gutter-x-md">
                <q-input outlined disable  v-model="form.id" type="text" :rules="[requiredTest]" />
              </div>
            </div>
          </div>

          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="col-5">
              <h5>
                <q-icon name="star" color="red" />文章标题：
              </h5>
              <div class=" q-col-gutter-x-md">
                <q-input outlined    v-model="form.title" type="text" :rules="[requiredTest]" />
              </div>
            </div>
          </div>

          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="col-5">
              <h5>
                 文章描述：
              </h5>
              <div class=" q-col-gutter-x-md">
                <q-input outlined    v-model="form.description" type="text" />
              </div>
            </div>
          </div>

          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="col-3">
              <h5>
                <q-icon name="star" color="red" />文章是否显示：
              </h5>
              <div class=" q-col-gutter-x-md">
                <q-toggle v-model="form.visibility" color="green" :rules="[requiredTest]"   />
              </div>
            </div>
          </div>

          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="col-3">
              <h5>
                <q-icon name="star" color="red" />是否首页显示：
              </h5>
              <div class=" q-col-gutter-x-md">
                <q-toggle v-model="form.top" color="green" :rules="[requiredTest]"   />
              </div>
            </div>
          </div>

          <div class="row q-col-gutter-x-md dialog_form q-pa-md">
            <div class="col-8">
              <h5>
                <q-icon name="star" color="red" />文章内容：
              </h5>
              <div class=" q-col-gutter-x-md">
                <q-editor  v-model="form.content"  :definitions="{ bold: {label: 'Bold', icon: null, tip: 'My bold tooltip'} }"  :rules="[requiredTest]" />
              </div>
            </div>
          </div>

          <div class="row q-col-gutter-x-md dialog_form q-pa-md"></div>
        </q-scroll-area>
        <div class="row justify-center q-pa-md">
          <q-btn outline color="primary" icon="mdi-close-thick" label="关闭" v-close-popup />
          <q-btn class="q-mx-sm" color="primary" icon="mdi-check-bold" label="提交" type="submit" />
        </div>
      </q-form>
    </q-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
  </q-page>
</template>

<script>
import { IndexMixin } from 'boot/mixins';
import confirm from 'components/confirm';
import { requiredTest } from 'boot/inputTest';
import { date } from 'quasar';
const today = new Date()
const { addToDate, subtractFromDate } = date
export default {
  name: 'ArticleList',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      columns: [
        {
          name: 'id', align: 'center', label: 'id', field: 'id',
        },
        {
          name: 'title', align: 'left', label: '文章标题', field: 'title',
        },
        {
          name: 'keywords', align: 'left', label: '关键词', field: 'keywords',
        },
        {
          name: 'visibility', align: 'left', label: '是否显示', field: 'visibility',
        },
        { top: 'top', align: 'left', label: '是否在首页显示', field: 'top', },
        { top: 'sort', align: 'left', label: '排序号', field: 'sort', },
        {
          name: 'opt', align: 'center', label: '操作', field: 'id',
        },
      ],
      showQuery: true,
      headers: [{ name: 'Authorization', value: localStorage.Authorization }],
      uploadUrl: `${process.env.BASE_URL}/sys/common/upload`,
      imgUrl: `${process.env.BASE_URL}/sys/common/static`,
      url: {
        list: '/articlelist',
        add: '/articleadd',
        edit: '/articleupdate',
        detail: 'articledetail',
        delete: '/articledelete',
        deleteBatch: '/mnt/app/deleteBatch',
        exportXlsUrl: '/mnt/app/exportXls',
        importExcelUrl: '/mnt/app/importExcel',
      },
      topType: [{ value: '1', label: '显示' }, { value: '0', label: '隐藏' }],

    };
  },
  methods: {
    requiredTest,
    addBefore() {
      this.form.catalogId = this.catalog;
      return true;
    },
    selectCatalog(n) {
      this.catalog = n;
      this.query();
    },
    getTypeLabel( b ){
      console.log(b)
      if(b == 0){
        return '隐藏'
      }else{
        return '显示'
      }

    },
    initDict() {
    },
    refresh(){
      this.$axios.get('/articlelist').then((r) => {
        this.list = r.data;
      });
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus"></style>
